home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / graphics 2d / quickdraw fx / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.2 KB  |  254 lines

  1. /*
  2.     File:        menu.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Edgar Lee    
  7.  
  8.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/13/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #include "FX.h"
  25. #include <Menus.h>
  26. #include <Resources.h>
  27. #include <ToolUtils.h>
  28. #include <Devices.h>
  29. #include <Fonts.h>
  30.  
  31. enum {
  32.     appleID = 128,
  33.     fileID = 129,
  34.     exID = 130,
  35.     srcID = 131
  36. };
  37.  
  38. enum {
  39.     quitItem = 1
  40. };
  41.  
  42. #define    WWIDTH        420
  43. #define    WHEIGHT        200
  44.  
  45. #define WLEFT        (((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - WWIDTH) / 2)
  46. #define WTOP        (((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - WHEIGHT) / 2)
  47.  
  48. void doAboutBox();
  49. void drawMyString();
  50.  
  51. void setUpMenus()
  52. {
  53.     Handle        menuHandle;
  54.     
  55.     if ((menuHandle = GetNewMBar( 128 )) == nil)
  56.         ExitToShell();
  57.         
  58.     SetMenuBar( menuHandle );
  59.     AppendResMenu( GetMenu( appleID ), 'DRVR' );
  60.         
  61.     DrawMenuBar();
  62.     ReleaseResource( menuHandle );
  63. }
  64.  
  65. void adjustMenus()
  66. {
  67.     int        i;
  68.  
  69.     EnableItem( GetMenuHandle( fileID ), quitItem );
  70.     
  71.     for (i = 1; i <= pixelAverageID; i++)
  72.         setMenuItem( GetMenuHandle( exID ), i, (i == gCurrentExample / 10) );
  73.     
  74.     setMenuItem( GetMenuHandle( exID ), customID + 1, (customID == gCurrentExample / 10) );
  75. }
  76.  
  77. void setMenuItem( menu, itemNum, enabled )
  78. MenuHandle    menu;
  79. int            itemNum;
  80. Boolean        enabled;
  81. {
  82.     if (enabled)
  83.         CheckItem( menu, itemNum, true );
  84.     else
  85.         CheckItem( menu, itemNum, false );
  86. }
  87.  
  88. void handleMenu( mSelect )
  89. long mSelect;
  90. {
  91.     int            menuID = HiWord( mSelect );
  92.     int            menuItem = LoWord( mSelect );
  93.     GrafPtr        savePort;
  94.     Str255        name;
  95.     long        ticks;
  96.  
  97.     switch (menuID)
  98.     {
  99.         case appleID:
  100.             if (menuItem == 1)
  101.                 doAboutBox();
  102.             else
  103.             {
  104.                 GetPort( &savePort );
  105.                 GetMenuItemText( GetMenu( appleID ), menuItem, name );
  106.                 OpenDeskAcc( name );
  107.                 SetPort( savePort );
  108.             }
  109.             break;
  110.             
  111.         case fileID:
  112.             if (menuItem)
  113.                 ExitToShell();
  114.             break;
  115.             
  116.         case exID:
  117.             if (menuItem == 10)
  118.                 menuItem--;
  119.  
  120.             if (menuItem == gCurrentExample / 10)
  121.                 break;
  122.             
  123.             if (menuItem == 9)
  124.                 resetItems();
  125.                 
  126.             gCurrentExample = (menuItem * 10) + 1;
  127.             drawExampleName();
  128.             drawSourceImage();
  129.             
  130.             ticks = drawFXImage();
  131.             drawTime( ticks );
  132.             drawAllItems();
  133.             break;
  134.             
  135.         case srcID:
  136.             createOffscreen( menuItem );
  137.             drawSourceImage();
  138.             
  139.             ticks = drawFXImage();
  140.             drawTime( ticks );
  141.             break;
  142.     }
  143.     
  144.     HiliteMenu( 0 );
  145. }
  146.  
  147. void doAboutBox()
  148. {
  149.     int                col, row;
  150.     int                width, height;
  151.     WindowPtr        window;
  152.     CIconHandle        cicn;
  153.     Rect            rect;
  154.     RGBColor        color;
  155.  
  156.     cicn = GetCIcon( 128 );
  157.     HPurge( (Handle)cicn );
  158.  
  159.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  160.     window = NewCWindow( 0L, &rect, "\p", true, plainDBox, (WindowPtr)-1L, false, 0L );                            
  161.     SetPort( window );
  162.         
  163.     TextFont( kFontIDGeneva );
  164.     TextMode( srcOr );
  165.     
  166.     color.red = color.green = color.blue = 8700;
  167.     RGBForeColor( &color );
  168.         
  169.     rect = window->portRect;
  170.     InsetRect( &rect, 1, 1 );
  171.     PaintRect( &rect );
  172.     
  173.     width = 32 * 6;
  174.     height = width;
  175.     
  176.     SetRect( &rect, 3, 3, width + 3, height + 3 );
  177.     PlotCIcon( &rect, cicn );
  178.  
  179.     ForeColor( blackColor );
  180.  
  181.     for (row = 6; row < height; row += 6)
  182.     {
  183.         MoveTo( rect.left, rect.top + row );
  184.         LineTo( rect.left + width, rect.top + row );
  185.     }
  186.     
  187.     for (col = 6; col < width; col += 6)
  188.     {
  189.         MoveTo( rect.left + col, rect.top );
  190.         LineTo( rect.left + col, rect.top + height );
  191.     }
  192.     
  193.     col = width + 15;
  194.     row = 35;
  195.     
  196.     TextFont( kFontIDTimes );
  197.     TextSize( 36 );
  198.     
  199.     color.blue = 0xffff;
  200.     color.red = color.green = 0;
  201.     RGBForeColor( &color );    
  202.     drawMyString( col, &row, 30, "\pQuickDraw™" );
  203.     
  204.     color.blue = 0x9fff;
  205.     RGBForeColor( &color );
  206.     drawMyString( col + 45, &row, -5, "\pFX" );
  207.     
  208.     TextFont( kFontIDGeneva );
  209.     TextSize( 9 );
  210.     ForeColor( whiteColor );
  211.     
  212.     col += 10;
  213.     
  214.     drawMyString( col + 115, &row, 25, "\pVersion 1.0" );
  215.     drawMyString( col, &row, 20, "\pBrought to you by Edgar Lee." );
  216.     
  217.     drawMyString( col, &row, 13, "\pFor any suggestions or comments," );
  218.     drawMyString( col, &row, 13, "\pplease write to edgar@apple.com" );
  219.     drawMyString( col, &row, 20, "\por appleLink EDGAR." );
  220.     
  221.     drawMyString( col, &row, 15, "\p© 1992-1999 Apple Computer, Inc." );
  222.     drawMyString( col, &row, 25, "\pAll rights reserved." );
  223.     
  224.     TextFont( kFontIDTimes );
  225.     TextSize( 36 );
  226.     
  227.     color.green = 0x8fff;
  228.     color.red = color.blue = 0;
  229.     RGBForeColor( &color );
  230.     drawMyString( col + 125, &row, 0, "\pDTS" );
  231.     
  232.     while (!Button());
  233.     
  234.     DisposeWindow( window );
  235. }
  236.  
  237. void drawMyString( col, row, increment, string )
  238. int        col, *row, increment;
  239. Str255    string;
  240. {
  241.     RGBColor    color;
  242.     
  243.     GetForeColor( &color );
  244.     
  245.     ForeColor( blackColor );
  246.     MoveTo( col + 2, *row + 2 );
  247.     DrawString( string );
  248.     
  249.     RGBForeColor( &color );
  250.     MoveTo( col, *row );
  251.     DrawString( string );
  252.     
  253.     *row += increment;
  254. }